package com.fdd.furns.dao.impl;

import com.fdd.furns.dao.BasicDAO;
import com.fdd.furns.dao.MemberDAO;
import com.fdd.furns.entity.Member;

public class MemberDAOImpl extends BasicDAO<Member> implements MemberDAO {

    /**
     * 提供一个方法，根据用户名返回Member对象
     * @param username  用户名
     * @return Member对象，如果没有返回null
     */
    @Override
    public Member queryMemberByUsername(String username) {
        String sql ="select * from member where username = ?";
        return querySingle(sql, Member.class, username);
    }



    /**
     * 提供一个方法，保存一个新的会员
     * @param member  会员对象
     * @return  返回-1 表示保存失败， 其他表示保存成功
     */
    @Override
    public int saveMember(Member member) {
        String sql = "insert into `member` (`username`,`password`,`email`) VALUES(?,MD5(?),?)";
        return update(sql, member.getUsername(), member.getPassword(), member.getEmail());
    }

    @Override
    public Member queryMemberByUsernameAndPassword(String username, String password) {
        String sql = "select * from member where username =? and password = MD5(?)";
        return querySingle(sql,Member.class,username,password);
    }
}
